import time
from config.config import config
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class page(config):
    # /html/body/div
    dy1_loc = (By.XPATH,'/html/body/div')
    def dy1(self):
        return self.text(self.dy1_loc)
    # id="chat-textarea"
    if(By.ID == "chat-textarea"):
        search_loc = (By.ID,'id="chat-textarea"')
        def search(self):
            self.send_keys(self.search_loc,'软件测试自动化')
    else:
        search_loc = (By.ID, 'kw')
        def search(self):
            self.send_keys(self.search_loc, '软件测试自动化')

    # id="chat-submit-button"
    if(By.ID == 'chat-submit-button'):
        search_btn_loc = (By.ID,'chat-submit-button')
        def search_btn(self):
            self.click(self.search_btn_loc)
    else:
        search_btn_loc = (By.ID, 'su')
        def search_btn(self):
            self.click(self.search_btn_loc)

    # /html/body/div[3]/div[4]/div[1]/div[3]
    get_all_loc = (By.XPATH,'/html/body/div[3]/div[4]/div[1]/div[3]')
    def get_all(self):
        return self.find_elements(self.get_all_loc)

    dy2_loc = (By.XPATH, '/html/body/div[3]/div[4]/div[1]/div[3]')
    def dy2(self):
        return self.find_elements(self.dy2_loc)

    # /html/body/div[3]/div[4]/div[2]/div/div/a[11]
    next_loc = (By.XPATH,'/html/body/div[3]/div[4]/div[2]/div/div/a[11]')
    def next(self):
        self.click(self.next_loc)

    # /html/body/div[3]/div[4]/div[1]/div[3]
    get_all2_loc = (By.XPATH,'/html/body/div[3]/div[4]/div[1]/div[3]')
    def get_all2(self):
        return self.find_elements(self.get_all2_loc)

    def luoji_01(self):
        self.open_url('https://www.baidu.com/')
        self.driver.implicitly_wait(10)
        assert "Baidu" in self.dy1()
        self.search()
        self.search_btn()
        time.sleep(5)
        self.get_all()
        # assert "软件测试" in self.dy2()
        time.sleep(3)
        # (WebDriverWait(self.driver,20,0.5).
         # until(EC.presence_of_element_located(self.next())))
        self.next()
        time.sleep(5)
        self.get_all2()
        # assert "软件测试" in self.dy2()
        time.sleep(3)